home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / enscript.4 / enscript / enscript-1.4.0 / afmlib / deffont.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-28  |  8.0 KB  |  383 lines

  1. /* 
  2.  * The default font.
  3.  * Copyright (c) 1995 Markku Rossi.
  4.  *
  5.  * Author: Markku Rossi <mtr@iki.fi>
  6.  */
  7.  
  8. /*
  9.  * This file is part of the AFM library.
  10.  * 
  11.  * This library is free software; you can redistribute it and/or
  12.  * modify it under the terms of the GNU Library General Public
  13.  * License as published by the Free Software Foundation; either
  14.  * version 2 of the License, or (at your option) any later version.
  15.  *
  16.  * This library is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19.  * Library General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU Library General Public
  22.  * License along with this library; if not, write to the Free
  23.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25.  
  26. #include "afmint.h"
  27. #include "afm.h"
  28.  
  29.  
  30. /*
  31.  * Static variables.
  32.  */
  33.  
  34. static AFMEncodingTable builtin_courier[] =
  35. {
  36.   {32,     "space"},
  37.   {33,     "exclam"},
  38.   {34,     "quotedbl"},
  39.   {35,     "numbersign"},
  40.   {36,     "dollar"},
  41.   {37,     "percent"},
  42.   {38,     "ampersand"},
  43.   {39,     "quoteright"},
  44.   {40,     "parenleft"},
  45.   {41,     "parenright"},
  46.   {42,     "asterisk"},
  47.   {43,     "plus"},
  48.   {44,     "comma"},
  49.   {45,     "hyphen"},
  50.   {46,     "period"},
  51.   {47,     "slash"},
  52.   {48,     "zero"},
  53.   {49,     "one"},
  54.   {50,     "two"},
  55.   {51,     "three"},
  56.   {52,     "four"},
  57.   {53,     "five"},
  58.   {54,     "six"},
  59.   {55,     "seven"},
  60.   {56,     "eight"},
  61.   {57,     "nine"},
  62.   {58,     "colon"},
  63.   {59,     "semicolon"},
  64.   {60,     "less"},
  65.   {61,     "equal"},
  66.   {62,     "greater"},
  67.   {63,     "question"},
  68.   {64,     "at"},
  69.   {65,     "A"},
  70.   {66,     "B"},
  71.   {67,     "C"},
  72.   {68,     "D"},
  73.   {69,     "E"},
  74.   {70,     "F"},
  75.   {71,     "G"},
  76.   {72,     "H"},
  77.   {73,     "I"},
  78.   {74,     "J"},
  79.   {75,     "K"},
  80.   {76,     "L"},
  81.   {77,     "M"},
  82.   {78,     "N"},
  83.   {79,     "O"},
  84.   {80,     "P"},
  85.   {81,     "Q"},
  86.   {82,     "R"},
  87.   {83,     "S"},
  88.   {84,     "T"},
  89.   {85,     "U"},
  90.   {86,     "V"},
  91.   {87,     "W"},
  92.   {88,     "X"},
  93.   {89,     "Y"},
  94.   {90,     "Z"},
  95.   {91,     "bracketleft"},
  96.   {92,     "backslash"},
  97.   {93,     "bracketright"},
  98.   {94,     "asciicircum"},
  99.   {95,     "underscore"},
  100.   {96,     "quoteleft"},
  101.   {97,     "a"},
  102.   {98,     "b"},
  103.   {99,     "c"},
  104.   {100,    "d"},
  105.   {101, "e"},
  106.   {102, "f"},
  107.   {103, "g"},
  108.   {104, "h"},
  109.   {105, "i"},
  110.   {106, "j"},
  111.   {107, "k"},
  112.   {108, "l"},
  113.   {109, "m"},
  114.   {110, "n"},
  115.   {111, "o"},
  116.   {112, "p"},
  117.   {113, "q"},
  118.   {114, "r"},
  119.   {115, "s"},
  120.   {116, "t"},
  121.   {117, "u"},
  122.   {118, "v"},
  123.   {119, "w"},
  124.   {120, "x"},
  125.   {121, "y"},
  126.   {122, "z"},
  127.   {123, "braceleft"},
  128.   {124, "bar"},
  129.   {125, "braceright"},
  130.   {126, "asciitilde"},
  131.   {161, "exclamdown"},
  132.   {162, "cent"},
  133.   {163, "sterling"},
  134.   {164, "fraction"},
  135.   {165, "yen"},
  136.   {166, "florin"},
  137.   {167, "section"},
  138.   {168, "currency"},
  139.   {169, "quotesingle"},
  140.   {170, "quotedblleft"},
  141.   {171, "guillemotleft"},
  142.   {172, "guilsinglleft"},
  143.   {173, "guilsinglright"},
  144.   {174, "fi"},
  145.   {175, "fl"},
  146.   {177, "endash"},
  147.   {178, "dagger"},
  148.   {179, "daggerdbl"},
  149.   {180, "periodcentered"},
  150.   {182, "paragraph"},
  151.   {183, "bullet"},
  152.   {184, "quotesinglbase"},
  153.   {185, "quotedblbase"},
  154.   {186, "quotedblright"},
  155.   {187, "guillemotright"},
  156.   {188, "ellipsis"},
  157.   {189, "perthousand"},
  158.   {191, "questiondown"},
  159.   {193, "grave"},
  160.   {194, "acute"},
  161.   {195, "circumflex"},
  162.   {196, "tilde"},
  163.   {197, "macron"},
  164.   {198, "breve"},
  165.   {199, "dotaccent"},
  166.   {200, "dieresis"},
  167.   {202, "ring"},
  168.   {203, "cedilla"},
  169.   {205, "hungarumlaut"},
  170.   {206, "ogonek"},
  171.   {207, "caron"},
  172.   {208, "emdash"},
  173.   {225, "AE"},
  174.   {227, "ordfeminine"},
  175.   {232, "Lslash"},
  176.   {233, "Oslash"},
  177.   {234, "OE"},
  178.   {235, "ordmasculine"},
  179.   {241, "ae"},
  180.   {245, "dotlessi"},
  181.   {248, "lslash"},
  182.   {249, "oslash"},
  183.   {250, "oe"},
  184.   {251, "germandbls"},
  185.   {-1,     "Aacute"},
  186.   {-1,     "Acircumflex"},
  187.   {-1,     "Adieresis"},
  188.   {-1,     "Agrave"},
  189.   {-1,     "Aring"},
  190.   {-1,     "Atilde"},
  191.   {-1,     "Ccedilla"},
  192.   {-1,     "Eacute"},
  193.   {-1,     "Ecircumflex"},
  194.   {-1,     "Edieresis"},
  195.   {-1,     "Egrave"},
  196.   {-1,     "Eth"},
  197.   {-1,     "Gcaron"},
  198.   {-1,     "IJ"},
  199.   {-1,     "Iacute"},
  200.   {-1,     "Icircumflex"},
  201.   {-1,     "Idieresis"},
  202.   {-1,     "Idot"},
  203.   {-1,     "Igrave"},
  204.   {-1,     "LL"},
  205.   {-1,     "Ntilde"},
  206.   {-1,     "Oacute"},
  207.   {-1,     "Ocircumflex"},
  208.   {-1,     "Odieresis"},
  209.   {-1,     "Ograve"},
  210.   {-1,     "Otilde"},
  211.   {-1,     "Scaron"},
  212.   {-1,     "Scedilla"},
  213.   {-1,     "Thorn"},
  214.   {-1,     "Uacute"},
  215.   {-1,     "Ucircumflex"},
  216.   {-1,     "Udieresis"},
  217.   {-1,     "Ugrave"},
  218.   {-1,     "Yacute"},
  219.   {-1,     "Ydieresis"},
  220.   {-1,     "Zcaron"},
  221.   {-1,     "aacute"},
  222.   {-1,     "acircumflex"},
  223.   {-1,     "adieresis"},
  224.   {-1,     "agrave"},
  225.   {-1,     "aring"},
  226.   {-1,     "arrowboth"},
  227.   {-1,     "arrowdown"},
  228.   {-1,     "arrowleft"},
  229.   {-1,     "arrowright"},
  230.   {-1,     "arrowup"},
  231.   {-1,     "atilde"},
  232.   {-1,     "brokenbar"},
  233.   {-1,     "ccedilla"},
  234.   {-1,     "center"},
  235.   {-1,     "copyright"},
  236.   {-1,     "dectab"},
  237.   {-1,     "degree"},
  238.   {-1,     "divide"},
  239.   {-1,     "down"},
  240.   {-1,     "eacute"},
  241.   {-1,     "ecircumflex"},
  242.   {-1,     "edieresis"},
  243.   {-1,     "egrave"},
  244.   {-1,     "eth"},
  245.   {-1,     "format"},
  246.   {-1,     "gcaron"},
  247.   {-1,     "graybox"},
  248.   {-1,     "iacute"},
  249.   {-1,     "icircumflex"},
  250.   {-1,     "idieresis"},
  251.   {-1,     "igrave"},
  252.   {-1,     "ij"},
  253.   {-1,     "indent"},
  254.   {-1,     "largebullet"},
  255.   {-1,     "left"},
  256.   {-1,     "lira"},
  257.   {-1,     "ll"},
  258.   {-1,     "logicalnot"},
  259.   {-1,     "merge"},
  260.   {-1,     "minus"},
  261.   {-1,     "mu"},
  262.   {-1,     "multiply"},
  263.   {-1,     "notegraphic"},
  264.   {-1,     "ntilde"},
  265.   {-1,     "oacute"},
  266.   {-1,     "ocircumflex"},
  267.   {-1,     "odieresis"},
  268.   {-1,     "ograve"},
  269.   {-1,     "onehalf"},
  270.   {-1,     "onequarter"},
  271.   {-1,     "onesuperior"},
  272.   {-1,     "otilde"},
  273.   {-1,     "overscore"},
  274.   {-1,     "plusminus"},
  275.   {-1,     "prescription"},
  276.   {-1,     "registered"},
  277.   {-1,     "return"},
  278.   {-1,     "scaron"},
  279.   {-1,     "scedilla"},
  280.   {-1,     "square"},
  281.   {-1,     "stop"},
  282.   {-1,     "tab"},
  283.   {-1,     "thorn"},
  284.   {-1,     "threequarters"},
  285.   {-1,     "threesuperior"},
  286.   {-1,     "trademark"},
  287.   {-1,     "twosuperior"},
  288.   {-1,     "uacute"},
  289.   {-1,     "ucircumflex"},
  290.   {-1,     "udieresis"},
  291.   {-1,     "ugrave"},
  292.   {-1,     "up"},
  293.   {-1,     "yacute"},
  294.   {-1,     "ydieresis"},
  295.   {-1,     "zcaron"},
  296.   {0, NULL},
  297. };
  298.  
  299. #define NUM_CHARACTER_METRICS \
  300.   (sizeof (builtin_courier) / sizeof (AFMEncodingTable) - 1)
  301.  
  302. /*
  303.  * Public functions.
  304.  */
  305.  
  306. AFMError
  307. afm_open_default_font (AFMHandle handle, AFMFont *font_return)
  308. {
  309.   AFMFont font;
  310.   AFMIndividualCharacterMetrics *cm;
  311.   int i;
  312.  
  313.   /* Alloc memory. */
  314.  
  315.   font = (AFMFont) calloc (1, sizeof (*font));
  316.   if (font == NULL)
  317.     goto error_out;
  318.   font->private
  319.     = (struct afm_font_private_data_st *) calloc (1, sizeof (*font->private));
  320.   if (font->private == NULL)
  321.     goto error_out;
  322.   font->private->fontnames = strhash_init ();
  323.   if (font->private->fontnames == NULL)
  324.     goto error_out;
  325.  
  326.   /* Version. */
  327.   font->version = 4.0;
  328.  
  329.   /* Global Font Info. */
  330.  
  331.   font->global_info.FontName = (char *) malloc (strlen ("Courier") + 1);
  332.   if (font->global_info.FontName == NULL)
  333.     goto error_out;
  334.   strcpy (font->global_info.FontName, "Courier");
  335.  
  336.   font->global_info.FontBBox_llx = -40.0;
  337.   font->global_info.FontBBox_lly = -290.0;
  338.   font->global_info.FontBBox_urx = 640.0;
  339.   font->global_info.FontBBox_ury = 795.0;
  340.  
  341.   /* Writing directions. */
  342.   font->writing_direction_metrics[0].is_valid = AFMTrue;
  343.   font->writing_direction_metrics[0].IsFixedPitch = AFMTrue;
  344.   font->writing_direction_metrics[0].CharWidth_x = 600.0;
  345.   font->writing_direction_metrics[0].CharWidth_y = 0.0;
  346.  
  347.   /* Character Metrics. */
  348.  
  349.   font->num_character_metrics = NUM_CHARACTER_METRICS;
  350.   font->character_metrics
  351.     = (AFMIndividualCharacterMetrics *)
  352.       calloc (NUM_CHARACTER_METRICS, sizeof (AFMIndividualCharacterMetrics));
  353.   if (font->character_metrics == NULL)
  354.     goto error_out;
  355.  
  356.   for (i = 0; builtin_courier[i].character; i++)
  357.     {
  358.       cm = &font->character_metrics[i];
  359.       cm->name = (char *) malloc (strlen (builtin_courier[i].character) + 1);
  360.       if (cm->name == NULL)
  361.     goto error_out;
  362.       strcpy (cm->name, builtin_courier[i].character);
  363.       
  364.       if (!strhash_put (font->private->fontnames, cm->name,
  365.             strlen (cm->name), cm, NULL))
  366.     goto error_out;
  367.  
  368.       cm->character_code = builtin_courier[i].code;
  369.       cm->w0x = 600.0;
  370.       cm->w0y = 0.0;
  371.     }
  372.  
  373.   *font_return = font;
  374.  
  375.   return AFM_SUCCESS;
  376.     
  377.  
  378.  error_out:
  379.   (void) afm_close_font (font);
  380.  
  381.   return AFM_ERROR_MEMORY;
  382. }
  383.